package cn.apotato.dynamicdatascore.config;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * 租户上下文持有者
 *
 * @author xphu
 * @date 2024/08/14
 */
@Component
public class TenantContext implements ApplicationContextAware {

    private static final ThreadLocal<String> contextHolder = new ThreadLocal<>();

    public static String getTenantId() {
        return contextHolder.get();
    }

    public static void setTenantId(String tenantId) {
        contextHolder.set(tenantId);
    }

    public static void clearTenantId() {
        contextHolder.remove();
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        // 初始化上下文
    }
}
